package com.fengye.lock.example;

/**
 *
 * @author sky
 * @date 2021年06月11日 9:16 上午
 */

public class LockThreadExample {

    public static void main(String[] args) {
        Thread tADD = new Thread(new LockThread(100));
        Thread tSub = new Thread(new LockThread(-100));
        tADD.start();
        tSub.start();
    }
}

// class LockOne{
//
// }

class LockThread implements Runnable {
    private int count = 0;

    public LockThread(int count) {
        this.count = count;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            synchronized (SysConstant.amount) {
                SysConstant.amount = SysConstant.amount + count;
                System.out.println("此时账户余额为： " + SysConstant.amount);
            }

        }
    }
}
